const inquirer = require("inquirer");

inquirer
  .prompt([
      {
          type: "input",
          name: "name",// 必传  作为键值对中key出现
          message: "your name",
          default: "defaultName",
          validate: (msg) => {// 输入校验
              if(msg.startsWith("@luban/aa") === true) {
                  return true;
              }
              console.log("\n 请重新输出");
              return false;
          },
          transformer(v){// 展示修改  不影响最终修改
              return `name[${v}]`
          },
          filter(v) {// 修改输出，在校验之前
              return `@luban/${v}`
          }
      },
      {
          type: "number",
          name: "age",
          message: "your age"
      }
  ])
  .then((answers) => {
      console.log(answers);
    // Use user feedback for... whatever!!
  })
  .catch((error) => {
    if (error.isTtyError) {
      // Prompt couldn't be rendered in the current environment
    } else {
      // Something else went wrong
    }
  });
